// Copyright (c) 2009 Mike Haight, Andy Kipp
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

#include "stdafx.h"

#pragma once

namespace HandBanana { namespace Core { namespace Graphics
{
#ifdef _D3D10_1
    private enum class DriverType
    {
        Hardware = D3D10_DRIVER_TYPE_HARDWARE,
        Warp = D3D10_DRIVER_TYPE_WARP,
        Reference = D3D10_DRIVER_TYPE_REFERENCE,
    };


    private enum class FeatureLevel
    {
        Ten_1 = D3D10_FEATURE_LEVEL_10_1,
        Ten_0 = D3D10_FEATURE_LEVEL_10_0,
        Nine_3 = D3D10_FEATURE_LEVEL_9_3,
        Nine_2 = D3D10_FEATURE_LEVEL_9_2,
        Nine_1 = D3D10_FEATURE_LEVEL_9_1,
    };
#endif

    /// <summary>
    /// Provides a base class for rendering to a window.
    /// </summary> 
    public ref class Renderer sealed
    {
    // Constructor
    public:
        Renderer(Window^ argWindow);


    // Destructor
    public:
        ~Renderer(void);


    // Public Methods
    public:
        void BeginDrawing(void);

        void Clear(void);

        IntPtr CreateTexture(String^ argFileName);

        void Draw(List<Sprite^>^ argSprites);

        void EndDrawing(void);

        void Present(void);

        void SetView(Coordinates::Rectangle argRectangle);


    // Private Data Members
    private:
        void Start(void);

        void Stop(void);

        void WindowResized(Object^ argSender, SizedEventArgs^ e);


    // Private Data Members
    private:
        // Logger
        static NLog::Logger^    smLogger = NLog::LogManager::GetCurrentClassLogger();

        // State
        Coordinates::Rectangle  mViewRectangle;
        Window^                 mWindow;
        SizedEventHandler^      mWindowSized;

        #ifdef _D3D10_1
            // D3D10 Api State
            ID3D10BlendState*       mBlendState;
            ID3D10Device1*          mDevice;
            ID3D10RenderTargetView* mRenderTargetView;
            ID3DX10Sprite*          mSprite;
            IDXGISwapChain*         mSwapChain;
        #else
        #ifdef _D3D9
            // D3D9 Api State
            IDirect3D9*             mInterface;
            IDirect3DDevice9*       mDevice;
            ID3DXSprite*            mSprite;
        #endif /* _D3D9 */
        #endif /* _D3D10_1 */
    };

} } }